package com.example.myDesignPatterns.行为型模式.责任链模式Responsibility.用责任链模式处理全局异常.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/api")
public class TestController {

    @GetMapping("/divide")
    public double divideNumbers() {
        return 10 / 0; // 将触发 ArithmeticException
    }

    @GetMapping("/read-file")
    public String readFile() throws IOException {
        // 故意触发 IOException
        throw new IOException("File not found");
    }

    @GetMapping("/generic-error")
    public String genericError() {
        // 故意触发 RuntimeException
        throw new RuntimeException("A generic error occurred");
    }
}